﻿@page "/range-selector/multilevel"
@using Newtonsoft.Json
@using  Syncfusion.Blazor.Charts
@using Syncfusion.Blazor
@inject NavigationManager NavigationManager
@inherits SampleBaseComponent;

<SampleDescription>
    <p>Axis labels are placed based on the values of the start and end ranges. You can add higher level of labels to the range navigator using multilevel labels.</p>
</SampleDescription>
<ActionDescription>
    <p>In this example, you can see how to group the axis labels. Here the interval for the second level labels can be customized using <code>groupBy</code>.</p>
</ActionDescription>

@if (MultiLevelData == null)
{
    <div class="stockchartloader"></div>
}
else
{
    <div class="control-section">
        <br>
        <h4 style="font-family: Segoe UI;font-weight: 500; font-style:normal; font-size:15px; text-align:center">Multi Level Labels</h4>
        <div align="center">
            <SfRangeNavigator LabelPosition="AxisPosition.Outside" Theme="@RangeNavigatorTheme" EnableGrouping="true" GroupBy="RangeIntervalType.Years" Value="@RangeValue" IntervalType="RangeIntervalType.Quarter" ValueType="Syncfusion.Blazor.Charts.RangeValueType.DateTime" DataSource="@MultiLevelData" XName="x" YName="low">
                <RangeNavigatorRangeTooltipSettings Enable="true" DisplayMode="TooltipDisplayMode.Always"></RangeNavigatorRangeTooltipSettings>
            </SfRangeNavigator>
        </div>
    </div>
}
@code{

    public Theme RangeNavigatorTheme { get; set; }
    public ChartData[] MultiLevelData { get; set; }
    public object[] RangeValue { get; set; } = new object[] { new DateTime(2014, 01, 01), new DateTime(2016, 01, 01) };
    private string currentUri;

    protected override async Task OnInitializedAsync()
    {
        await Task.Run(() =>
        {
            MultiLevelData = JsonConvert.DeserializeObject<ChartData[]>(System.IO.File.ReadAllText("./wwwroot/data/range-navigator/chart-data.json"));
        });
    }

    public class ChartData
    {
        public DateTime x { get; set; }
        public double low { get; set; }
    }

    protected override void OnInitialized()
    {
        currentUri = NavigationManager.Uri;
        if (currentUri.IndexOf("material") > -1)
        {
            RangeNavigatorTheme = Theme.Material;
        }
        else if (currentUri.IndexOf("fabric") > -1)
        {
            RangeNavigatorTheme = Theme.Fabric;
        }
        else if (currentUri.IndexOf("bootstrap4") > -1)
        {
            RangeNavigatorTheme = Theme.Bootstrap4;
        }
        else if (currentUri.IndexOf("bootstrap") > -1)
        {
            RangeNavigatorTheme = Theme.Bootstrap;
        }
        else if (currentUri.IndexOf("highcontrast") > -1)
        {
            RangeNavigatorTheme = Theme.HighContrast;
        }
        else if (currentUri.IndexOf("tailwind") > -1)
        {
            RangeNavigatorTheme = Theme.Tailwind;
        }
        else
        {
            RangeNavigatorTheme = Theme.Bootstrap4;
        }
    }
}